import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/index/HomeView.vue'
import Login from '../views/login/login.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'login',
      component: Login
    },
    {
      path: '/home',
      name: 'home',
      component: HomeView,
      children:[
        {
          path: '/about',
          name: 'about',
          component: () => import('../views/index/AboutView.vue')
        },
        {
          path: '/abo',
          name: 'abo',
          component: () => import('../views/index/aboutl.vue')
        },
        {
          path: '/my',
          name: 'my',
          component: () => import('../views/my/my.vue')
        },
        {
          path: '/hole',
          name: 'hole',
          component: () => import('../views/qt/hole.vue')
        },
        {
          path: '/hola',
          name: 'hola',
          component: () => import('../views/qt/hola.vue')
        }
      ]
    },
  ]
});
router.beforeEach((to, from) => {
  if (to.path == "/home") {
    if (!localStorage.getItem("token")) {
      console.log(456);
      return "/";
    }
  }
  // return false;
});
export default router
